<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="人员名称" prop="name">
        <el-input v-model="queryParams.name"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['duty:gzrz:add']"
        >新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="gzrzList" @selection-change="handleSelectionChange">
      <el-table-column label="人员" align="center" prop="name" width="180"/>
      <el-table-column label="类型" align="center" prop="type" width="180">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.user_business_sub_type" :value="scope.row.subType"/>
        </template>
      </el-table-column>
      <el-table-column label="当前负责人数" align="center" prop="fzrCount" width="150"/>
      <el-table-column label="踏查次数" align="center" prop="tcCount" width="150"/>
      <el-table-column label="尿检审核次数" align="center" prop="jcjhCount" width="150"/>
      <el-table-column label="请假审核次数" align="center" prop="leaveCount" width="150"/>
      <el-table-column label="谈话次数" align="center" prop="thCount" width="150"/>
      <el-table-column label="禁毒宣传次数" align="center" prop="jdxcCount" width="150"/>
      <el-table-column label="就业培训次数" align="center" prop="jypxCount" width="150"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="toDetailList(scope.row.memberId)">工作日志详情</el-button>
          <el-button size="mini" type="text" @click="openWarningDetailList(scope.row.memberId)">工作预警</el-button>
          <el-button size="mini" type="text" @click="openMgrUserList(scope.row.memberId)">人员管理详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <mgr-user-list ref="mul"/>
    <mgr-user-warning-list ref="muwl"/>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <rz-form ref="rzForm"/>
  </div>
</template>

<script>
import {queryGzrzFull} from "@/api/duty/gzrz";
import MgrUserList from "@/views/duty/gzrz/mgrUserList.vue";
import rzForm from "@/views/duty/gzrz/rzForm.vue";
import MgrUserWarningList from "@/views/duty/gzrz/mgrUserWarningList.vue";

export default {
  name: "Gzrz",
  components: {MgrUserList, rzForm, MgrUserWarningList},
  dicts: ['user_business_sub_type'],
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工作日志表格数据
      gzrzList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    openMgrUserList(memberId) {
      this.$refs.mul.open(memberId)
    },
    openWarningDetailList(memberId) {
      this.$refs.muwl.open(memberId)
    },
    toDetailList(memberId) {
      this.$router.push({path: '/duty/rz-detail/index', query: {memberId: memberId}})
    },
    /** 查询工作日志列表 */
    getList() {
      this.loading = true;
      queryGzrzFull(this.queryParams).then(response => {
        this.gzrzList = response.data;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        gzrzId: undefined,
        date: undefined,
        memberId: undefined,
        content: undefined,
        images: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.gzrzId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.rzForm.open()
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.rzForm.open(row)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('duty/gzrz/export', {
        ...this.queryParams
      }, `gzrz_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
